package com.ykdl.member.kid.circle;

import java.io.File;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.lang.ref.SoftReference;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

import net.wxxr.dataparse.model.DataParseError;
import net.wxxr.dataparse.model.DataState;
import net.wxxr.http.interfaces.ISaveUserInfoForAutoLoginSuccess;
import net.wxxr.http.interfaces.ITag;
import net.wxxr.http.request.HttpBaseRequest;
import oauth.signpost.http.HttpParameters;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.BitmapUtils;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.umeng.analytics.MobclickAgent;
import com.ykdl.member.kid.util.UmShareUtils;
import com.ykdl.member.kid.R;
import com.ykdl.member.KidApp;
import com.ykdl.member.base.QLog;
import com.ykdl.member.constant.KidAction;
import com.ykdl.member.constant.KidConfig;
import com.ykdl.member.kid.adapters.PopwindowAdapter;
import com.ykdl.member.kid.beans.ImageBean;
import com.ykdl.member.kid.beans.InformsBean;
import com.ykdl.member.kid.beans.OptionsBean;
import com.ykdl.member.kid.beans.ResultBean;
import com.ykdl.member.kid.beans.TopicAndPostBean;
import com.ykdl.member.kid.beans.TopicAndPostListBean;
import com.ykdl.member.kid.beans.TopicAndPostResultBean;
import com.ykdl.member.kid.beans.TopicBean;
import com.ykdl.member.kid.gears.BaseScreen;
import com.ykdl.member.kid.gears.ShareWeiBo;
import com.ykdl.member.kid.image.ImageLoader;
import com.ykdl.member.kid.image.ImageOptions;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.models.FileMetas;
import com.ykdl.member.kid.person.PersonCenterActivity;
import com.ykdl.member.kid.prefs.CircleStatePrefs;
import com.ykdl.member.kid.prefs.PostLikeNumberPre;
import com.ykdl.member.kid.regandlogin.RegAndLoginActivity;
import com.ykdl.member.kid.util.CameraHelp;
import com.ykdl.member.kid.util.DateUtil;
import com.ykdl.member.kid.util.WeiXinUtil;
import com.ykdl.member.kid.widget.AsyncImageView;
import com.ykdl.member.kid.widget.RefreshListView;
import com.ykdl.member.kid.widget.RefreshListView.OnRefreshListener;
import com.ykdl.member.kid.widget.dialog.DialogCallBack;
import com.ykdl.member.kid.widget.dialog.DialogImpl;
import com.ykdl.member.kid.widget.dialog.IDialog;
import com.ykdl.member.views.FocusTextView;
import com.ykdl.member.views.ResizeLayout;
import com.ykdl.member.views.SelectToolDataView;
import com.ykdl.net.manager.TaskManager;
import com.ykdl.net.manager.Wxxr;

public class TopicAndResultActivity extends BaseScreen implements OnClickListener{
	private RefreshListView topic_result_list ;
	private FocusTextView head_channel ;
	private TextView head_topicnum ,user_name,user_time,user_grade,user_age,
	user_address,user_content,user_choose_praise,main_title,user_tquestion,user_laye;
	private View header = null;
	private ImageView user_head ;
	private ImageView topic_picture1,topic_picture2,topic_picture3,topic_picture4;
	private Button  title_xiala,user_tool_but,topic_answer_send;
	private EditText topic_answer_input ;
	private TopicAndPostBean topicbean ;
	private String TAG = "TopicAndResultActivity";
	private ImageOptions options=null ;
	private ArrayList<TopicAndPostBean>  topicandpostlist = new ArrayList<TopicAndPostBean>() ;
	private TopicResultAdapter adapter ;
	private Dialog topic_tool_dialog ;
	private String parent_id ="";
	private String praised_item_type = "";
	private PostLikeNumberPre  praisesstate ;
	private String sum_count ;
	private String group_namestring;
	private PopupWindow m_popupWindow;
	private ListView mtListView;
	private ArrayList<OptionsBean> optionslist ;
	private int sort = -1 ;
	private int condition = -90 ;
	private String  topic_id ;
	private String  group_id ;
	private String  post_id=null ;
	private SelectToolDataView selToolData ;
	private ImageView photo1 ,photo2,photo3 ;
	private LinearLayout seltool_imgs, topic_user_pic;
	private RelativeLayout seltool_imgs_div_1,seltool_imgs_div_2,seltool_imgs_div_3;
	private ArrayList<SoftReference<Bitmap>> mBitmapRefs = new ArrayList<SoftReference<Bitmap>>();  
	private ArrayList<ImageBean> photopath = new ArrayList<ImageBean>();
	private ArrayList<ImageBean> nt_photopath = new ArrayList<ImageBean>();
	private int topic_praisecount  = 0;
	private int start_id = 0;
	private int cursor = 0;
	private int count = 20;
	private boolean issetleftlist= false;
	public static final String STR_TOPIC_ID = "topic_id";
	public static final String STR_GROUP_ID = "group_id";
	public static final String STR_POST_ID = "post_id";
	public static final String STR_REPORT_TYPE = "report_type";
	public static final String STR_REPORT_ID = "report_id";
	private BitmapUtils bitmapUtil ;
	private BitmapUtils picture_bitmapUtil ;
	private boolean is_praises = true ;
	private boolean is_clear_edite= true;
	private boolean top_is_praises= true;
	private DialogImpl  dialog = new DialogImpl();
	private KidApp mApplication ;
	private int start_int = 1;
	private com.ykdl.member.kid.util.UmShareUtils mUmShare;
	private FrameLayout mFrame;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.topicandresultactivity_xml);
		topic_id = getIntent().getStringExtra(STR_TOPIC_ID);
		group_id = getIntent().getStringExtra(STR_GROUP_ID);
		post_id = getIntent().getStringExtra(STR_POST_ID);
		mApplication=(KidApp) this.getApplication();
		bitmapUtil = new BitmapUtils(this);
		bitmapUtil.configDefaultLoadingImage(R.drawable.defualt_icon);
		bitmapUtil.configDefaultLoadFailedImage(R.drawable.defualt_icon);
		picture_bitmapUtil = new BitmapUtils(this);
		initUmShare();//
		findviewid();
	}
	public void findviewid() {
		mtListView = new ListView(this);
		options = ImageOptionsFactory.getBigPortraitOptions(TopicAndResultActivity.this);
		topic_result_list = (RefreshListView)findViewById(R.id.topic_result_list);
		head_channel = (FocusTextView)findViewById(R.id.head_channel);
		head_topicnum = (TextView)findViewById(R.id.head_topicnum);
		main_title =  (TextView)findViewById(R.id.main_title);
		topic_answer_input = (EditText)findViewById(R.id.topic_answer_input);
		topic_answer_input.setOnClickListener(this);
		topic_answer_send = (Button)findViewById(R.id.topic_answer_send);
		title_xiala = (Button) findViewById(R.id.title_xiala);
		title_xiala.setOnClickListener(this);
		topic_answer_send.setOnClickListener(this);
		header = LayoutInflater.from(mContext).inflate(
				R.layout.iask_topic_item, null);
		user_head = (ImageView) header.findViewById(R.id.user_head);
		user_name = (TextView) header.findViewById(R.id.user_name);
		user_time = (TextView) header.findViewById(R.id.user_time);
		user_grade = (TextView) header.findViewById(R.id.user_grade);
		user_age = (TextView) header.findViewById(R.id.user_age);
		user_address = (TextView) header.findViewById(R.id.user_address);
		user_content = (TextView) header.findViewById(R.id.user_content);
		user_tquestion = (TextView) header.findViewById(R.id.user_tquestion);
		user_laye = (TextView) header.findViewById(R.id.user_laye);
		user_tool_but = (Button) header.findViewById(R.id.user_tool_but);
		topic_user_pic = (LinearLayout) header.findViewById(R.id.topic_user_pic);
		user_tool_but.setOnClickListener(this);
		user_tquestion.setOnClickListener(this);
		user_choose_praise = (TextView) header.findViewById(R.id.user_choose_praise);
		user_choose_praise.setOnClickListener(this);
		topic_picture1= (ImageView) header.findViewById(R.id.topic_picture1);
		topic_picture2= (ImageView) header.findViewById(R.id.topic_picture2);
		topic_picture3= (ImageView) header.findViewById(R.id.topic_picture3);
		topic_picture4= (ImageView) header.findViewById(R.id.topic_picture4);
		adapter = new TopicResultAdapter();
		topic_result_list.addHeaderView(header);
		praisesstate = new PostLikeNumberPre(mContext);
		praisesstate.clearData();
		findViewById(R.id.main_left).setOnClickListener(this);
		ResizeLayout root = (ResizeLayout) findViewById(R.id.iask_main_root);
		root.setOnResizeListener(new ResizeLayout.OnResizeListener() {

			public void OnResize(int w, int h, int oldw, int oldh) {
				// int change = ResizeLayout.BIGGER;
				if (h < oldh) {
					// change = ResizeLayout.SMALLER;
				} else if (h - oldh > 200) {
					// 键盘的高度应该会大于这个值， 删除一个汉字，也会小于这个值，所以变化在200之外才是键盘隐藏，
					// 否则是用键盘在删除文字，不用处理
					if (is_clear_edite) {
						selToolData.setVisibility(View.GONE);
						topic_answer_send.setBackgroundResource(R.drawable.topic_send_bg_white);
					}
				}
			}
		});
		
		getTopiclist();
		selToolData = (SelectToolDataView)findViewById(R.id.share_data_panle);
		seltool_imgs = (LinearLayout)findViewById(R.id.seltool_imgs);
		selToolData.setOwerActivity(this);
		selToolData.setCheckBoxGon();
		selToolData.setEditText(topic_answer_input,seltool_imgs);
		photo1 = (ImageView)findViewById(R.id.photo1);
		photo2 = (ImageView)findViewById(R.id.photo2);
		photo3 = (ImageView)findViewById(R.id.photo3);
		findViewById(R.id.close1).setOnClickListener(this);
		findViewById(R.id.close2).setOnClickListener(this);
		findViewById(R.id.close3).setOnClickListener(this);
		seltool_imgs_div_1 = (RelativeLayout)findViewById(R.id.seltool_imgs_div_1);
		seltool_imgs_div_2 = (RelativeLayout)findViewById(R.id.seltool_imgs_div_2);
		seltool_imgs_div_3 = (RelativeLayout)findViewById(R.id.seltool_imgs_div_3);
		topic_result_list.setonRefreshListener(new OnRefreshListener() {

			@Override
			public void onRefresh() {
				// TODO Auto-generated method stub
				issetleftlist = false;
				count = 20;
				cursor = 0;
				topicandpostlist= new ArrayList<TopicAndPostBean>() ;
				getTopiclist();
			}});
		topic_result_list.setMoreClick(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				issetleftlist = true ;
				++start_int ;
				count =20 ;
				getTopiclist();
			}});
		findViewById(R.id.circle_linearlayout_tip).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent  = new Intent(mContext, CircleTopicActivity.class);
				intent.putExtra("group_id", group_id+"");
				startActivity(intent);
			}
		});
		mFrame = (FrameLayout) findViewById(R.id.frame_hidden);
	}
	public void setPopwindowAdapter(ArrayList<OptionsBean> optionslist) {
		final PopwindowAdapter lpopwindowAdapter = new PopwindowAdapter(this, optionslist);
		mtListView.setAdapter(lpopwindowAdapter);
		mtListView.setSelector(getResources().getDrawable(R.drawable.title_popsel));
		mtListView.setCacheColorHint(0);
		mtListView.setDivider(null);
		mtListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				OptionsBean bean = (OptionsBean)lpopwindowAdapter.getItem(arg2);
				main_title.setText(bean.getName());
				sort = bean.getParams().getSort();
				condition = bean.getParams().getCondition();
				count = 20;
				cursor = 0;
				topicandpostlist= new ArrayList<TopicAndPostBean>() ;
				m_popupWindow.dismiss();
				getTopiclist();
			}
			
		});
	}
	public void initPopupWindow(View view,ListView listview) {
		int popwidth =(int)this.getResources().getDimension(R.dimen.top_pop_width);
		int pophight =(int)this.getResources().getDimension(R.dimen.top_pop_hight);
		m_popupWindow = new PopupWindow(listview, popwidth, pophight,true);
		m_popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.title_popbk));
		WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);  
		int xPos = (-windowManager.getDefaultDisplay().getWidth() / 2)+m_popupWindow.getWidth()/2 ; 
		m_popupWindow.showAsDropDown(view,xPos,0);
		m_popupWindow.setOnDismissListener(new OnDismissListener() {
			
			@Override
			public void onDismiss() {
				// TODO Auto-generated method stub
				title_xiala.setSelected(false);
			}
		});
	}
	protected void onResume() {
		// TODO Auto-generated method stub
		ImageLoader.getInstance().setCurrentActivity(TAG);
		super.onResume();
	}
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		ImageLoader.getInstance().pause(TAG);
		super.onPause();
	}
	public void setData(final TopicAndPostBean bean) {
		if (bean==null) {
			return;
		}
		if (bean.getPost_actor()!=null) {
			if (bean.getIs_anonymous().equals("0")) {
				if (bean.getPost_actor().getAvatar_file_meta()!=null) {
					String url = bean.getPost_actor().getAvatar_file_meta().getDownload_urls().getSmal().getUrl();
					bitmapUtil.display(user_head, url);
				}
				user_head.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
							go(PersonCenterActivity.class, PersonCenterActivity.STR_ACTOR_ID, bean.getPost_actor().getActor_id());
					}
				});
				user_name.setText(bean.getPost_actor().getDisplay_name());
			}else {
				user_name.setText("匿名用户");
				user_head.setBackgroundResource(R.drawable.defualt_icon);
			}
			
			user_grade.setText(bean.getPost_actor().getLevel()+"");
			if (bean.getExtra_data()!=null) {
				user_address.setText(bean.getExtra_data().getBaby_address());
			}
			
		}
		
		user_laye.setText(bean.getLayer()+"楼");
		user_time.setText(DateUtil.gettopicDate(bean.getPost_time()));
		if (bean.getExtra_data()!=null) {
			if (null!=bean.getExtra_data().getBaby_days()) {
				switch (bean.getExtra_data().getStatus()) {
				case 1:
					user_age.setText(DateUtil.getDue_date(bean.getExtra_data().getBaby_days()));
					break;
				case 2:
					user_age.setText(DateUtil.getDayTip(bean.getExtra_data().getBaby_days()));
					break;
				case 3:
					user_age.setText("6岁+");
					break;
				default:
					user_age.setText("");
					break;
				}
			}else {
				user_age.setText("");
			}
		}else {
			user_age.setText("");
		}
		
		user_content.setText(bean.getMessage());
		if (bean.isHas_image()) {
			dopicdata(bean.getFile_metas());
		}
		topic_praisecount = bean.getLikes_count();
		if (bean.isIs_like()) {
			user_choose_praise.setSelected(true);
			user_choose_praise.setText(topic_praisecount+"");
			top_is_praises=true;
		}else {
			user_choose_praise.setSelected(false);
			user_choose_praise.setText(topic_praisecount+"");
			top_is_praises=false;
		}
		head_channel.setText(group_namestring);
		head_topicnum.setText(sum_count+"话题");
		if (bean.isIs_favorite()) {
			user_tquestion.setText("已收藏");
			user_tquestion.setTextColor(Color.parseColor("#ff9847"));
		}else {
			user_tquestion.setText("收藏");
		}
		user_tquestion.setSelected(bean.isIs_favorite());
	}
	public void dopicdata(final ArrayList<FileMetas> file_meta) {
		bitmapUtil.configDefaultLoadingImage(R.drawable.iask_main_middle_img);
		topic_user_pic.setVisibility(View.VISIBLE);
		if (file_meta.size()==1) {
			topic_picture1.setVisibility(View.GONE);
			topic_picture2.setVisibility(View.GONE);
			topic_picture3.setVisibility(View.GONE);
			topic_picture4.setVisibility(View.GONE);
			String url = file_meta.get(0).getDownload_urls().getBig().getUrl();
			bitmapUtil.display(topic_user_pic, url);
		}
		if (file_meta.size()==2) {
			topic_picture1.setVisibility(View.VISIBLE);
			topic_picture2.setVisibility(View.VISIBLE);
			topic_picture3.setVisibility(View.GONE);
			topic_picture4.setVisibility(View.GONE);
			String url = file_meta.get(0).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture1, url);
			String url2 = file_meta.get(1).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture2, url2);
		}
		if (file_meta.size()==3) {
			topic_picture1.setVisibility(View.VISIBLE);
			topic_picture2.setVisibility(View.VISIBLE);
			topic_picture3.setVisibility(View.VISIBLE);
			topic_picture4.setVisibility(View.GONE);
			String url = file_meta.get(0).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture1, url);
			String url2 = file_meta.get(1).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture2, url2);
			String url3= file_meta.get(2).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture3, url3);
		}
		if(file_meta.size()==4){
			topic_picture1.setVisibility(View.VISIBLE);
			topic_picture2.setVisibility(View.VISIBLE);
			topic_picture3.setVisibility(View.VISIBLE);
			topic_picture4.setVisibility(View.VISIBLE);
			String url = file_meta.get(0).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture1, url);
			String url2 = file_meta.get(1).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture2, url2);
			String url3= file_meta.get(2).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture3, url3);
			String url4= file_meta.get(3).getDownload_urls().getSmal().getUrl();
			bitmapUtil.display(topic_picture4, url4);
			
		}
		topic_user_pic
		.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				lookbigimage(file_meta, 0);
			}
		});
		topic_picture1.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				lookbigimage(file_meta, 0);
			}
		});
		topic_picture2.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				lookbigimage(file_meta, 1);
			}
		});
		topic_picture3.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				lookbigimage(file_meta, 2);
			}
		});
		topic_picture4.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				lookbigimage(file_meta, 3);
			}
		});
		
	}
	private void getTopiclist() {
		if (!issetleftlist) {
			showProgress("正在发送请稍等...");
		}
		String  pageurl;
		if (post_id!=null) {
			pageurl = KidConfig.GET_TOPICS_ANDPOSTS+group_id+"/topics/"+topic_id+"/"+post_id;
		}else {
			pageurl = KidConfig.GET_TOPICS_ANDPOSTS+group_id+"/topics/"+topic_id;
		}
		  
//		String  pageurl = "http://172.16.22.52:5000/api/v1/topics/posts/18";
		Map<String,String> map = new HashMap<String, String>();
		if (sort!=-1) {
			map.put("sort", sort+"");
		}
		if (condition!=-90) {
			map.put("condition", condition+"");
		}
		map.put("start_id", String.valueOf(start_id));
		map.put("cursor", String.valueOf(cursor));
		map.put("count", String.valueOf(count));
		HttpBaseRequest request  =  Wxxr.getInstance().getRequest(pageurl, map,null);
		 TaskManager.startHttpRequest(request, new getTopiclistTag(request),  TopicAndPostListBean.class);
	}
	class getTopiclistTag implements ITag {
		HttpBaseRequest request ;
		public getTopiclistTag(HttpBaseRequest request){
			this.request = request ;
		}
		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof TopicAndPostListBean) {
				TopicAndPostListBean bean = (TopicAndPostListBean)t;
				if (bean.getDesc()==null) {
					int index = 0;
					if (topicandpostlist.size() > 1) {
						index = topicandpostlist.size() - 1;
					}
					for (TopicAndPostBean obj : bean.getList()) {
						topicandpostlist.add(obj);
					}
//					topicandpostlist = bean.getList();
					user_tquestion.setSelected(bean.isIs_favorite());
					if (topicandpostlist!=null) {
						if (topicandpostlist.size()>=1) {
							 topicbean =topicandpostlist.get(0);
							topicandpostlist.remove(0);
							sum_count = bean.getGroup().getTopic_count()+"";
							group_namestring = bean.getGroup().getGroup_name();
							optionslist = bean.getGroup().getPost_options();
							setPopwindowAdapter(optionslist);
							setData( topicbean);
							adapter.setList(topicandpostlist);
							adapter.notifyDataSetChanged();
							if (bean.getNext_cursor() == bean.getTotal_number()) {
								topic_result_list.setMoreButtoIsGon(true);
							} else {
								cursor = bean.getNext_cursor();
								topic_result_list.setMoreButtoIsGon(false);
							}
							topic_result_list.setAdapter(adapter);
						}else {
							adapter.setList(topicandpostlist);
							topic_result_list.setAdapter(adapter);
						}
						if (issetleftlist) {
							topic_result_list.setSelection(index);
						}
						hidErrorTip( );
					}else {
						showErrorTip("没有数据...", "");
						topic_result_list.setMoreButtoIsGon(true);
					}
					topic_result_list.onRefreshComplete();
					topic_result_list.setFecthMoreOk();
					
					
				}else {
					Toast.makeText(mContext, "加载失败", 1).show();
				}
				
				
				
			}
			
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "加载失败", 1).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			request.cancel();
		}
		
	}
	class TopicResultAdapter extends BaseAdapter{
		ArrayList<TopicAndPostBean> list;
		Hashtable<String, String> openpraise = new Hashtable<String, String>();
		public void setList(ArrayList<TopicAndPostBean> list) {
			this.list = list;
		}
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			if (list != null) {
				return list.size();
			} else {
				return 0;
			}
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			 ViewHolder holder = null;
			if (convertView == null) {
				convertView = RelativeLayout.inflate(mContext,
						R.layout.iask_answer_item, null);
				 holder =  new ViewHolder();
				 holder.user_head =  (AsyncImageView) convertView.findViewById(R.id.user_head);
				 holder.topic_picture1 =  (ImageView) convertView.findViewById(R.id.topic_picture1);
				 holder.topic_picture2 =  (ImageView) convertView.findViewById(R.id.topic_picture2);
				 holder.topic_picture3 =  (ImageView) convertView.findViewById(R.id.topic_picture3);
				 holder.user_name=  (TextView) convertView.findViewById(R.id.user_name);
				 holder.user_grade=  (TextView) convertView.findViewById(R.id.grade);
				 holder.user_time=  (TextView) convertView.findViewById(R.id.user_time);
				 holder.user_age=  (TextView) convertView.findViewById(R.id.user_age);
				 holder.user_address=  (TextView) convertView.findViewById(R.id.user_address);
				 holder.user_content=  (TextView) convertView.findViewById(R.id.user_content);
				 holder.user_choose_praise=  (TextView) convertView.findViewById(R.id.user_choose_praise);
				 holder.topic_user_pic=  (LinearLayout) convertView.findViewById(R.id.topic_user_pic);
				 holder.reanswer_div=  (LinearLayout) convertView.findViewById(R.id.reanswer_div);
				 holder.topic_reanser_name=  (TextView) convertView.findViewById(R.id.topic_reanser_name);
				 holder.topic_reanser_content=  (TextView) convertView.findViewById(R.id.topic_reanser_content);
				 holder.user_result=  (Button) convertView.findViewById(R.id.user_result);
				 holder.user_tool_but=  (Button) convertView.findViewById(R.id.user_tool_but);
				 holder.user_laye=  (TextView) convertView.findViewById(R.id.user_laye);
				 convertView.setTag(holder);
				 }else {
					 holder = (ViewHolder) convertView.getTag();
				}
			
			
			
			final int  index=  position;
			holder.user_tool_but.setTag(list.get(position));
			holder.user_tool_but.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
				

					// TODO 调用友盟统计的分享
					TopicAndPostBean info = (TopicAndPostBean) v.getTag();
						
						if (mApplication.mMyUser.iAnonymousToken()) {
							showDialogImpl();
						}else {
							String imageUrl = null;
							if (info.isHas_image()) {
								imageUrl = info.getFile_metas().get(0).getDownload_urls().getBig().getUrl();
							}
							showtopictoolsdilog(info.getPost_id()+"","post",info.getMessage(),imageUrl);
						}
				}
			});
			 holder.user_result.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if (mApplication.mMyUser.iAnonymousToken()) {
						Intent intent=new Intent(TopicAndResultActivity.this,RegAndLoginActivity.class);
						intent.putExtra(KidAction.FROM, "");
						startActivity(intent);
					}else {
						showKeyBorad(topic_answer_input);
						parent_id = list.get(index).getPost_id()+"" ;
						topic_answer_send.setBackgroundResource(R.drawable.topic_send_bg);
					}
					
				}
			});
			 holder.user_laye.setText(list.get(position).getLayer()+"楼");
			 final  TopicAndPostBean top_postben= list.get(position) ;
			 if (is_praises) {
				 if (list.get(position).isIs_like()) {
					 holder.user_choose_praise.setSelected(true);
					 holder.user_choose_praise.setText(list.get(position).getLikes_count()+"");
					 praisesstate.setPraisesState(top_postben.getPost_id(),true);
				}else {
					 holder.user_choose_praise.setSelected(false);
					 holder.user_choose_praise.setText(list.get(position).getLikes_count()+"");
					 praisesstate.setPraisesState(top_postben.getPost_id(),false);
				}
			}
			
			 final TextView praise =  holder.user_choose_praise ;
			 holder.user_choose_praise.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						if (mApplication.mMyUser.iAnonymousToken()) {
							Intent intent=new Intent(TopicAndResultActivity.this,RegAndLoginActivity.class);
							intent.putExtra(KidAction.FROM, "");
							startActivity(intent);
						}else {
							if (top_postben.isIs_like()||praisesstate.getPraisesState(top_postben
									.getPost_id())) {
								Log.e("alan", "------is like----："+topicbean.isIs_like());
								deltpraises(top_postben.getPost_id(),false,praise);
							}else {
								addpraises(top_postben.getPost_id(),false,praise);
								Log.e("alan", "------no like----");
							}
						}
						
					}
				});
			 holder.user_name.setText(list.get(position).getPost_actor().getDisplay_name());
			 if (list.get(position).getPost_actor()!=null) {
				 if (list.get(position).getPost_actor().getAvatar_file_meta()!=null) {
						String url = list.get(position).getPost_actor().getAvatar_file_meta().getDownload_urls().getSmal().getUrl();
						bitmapUtil.display(holder.user_head, url);
						}else {
							holder.user_head.setImageResource(R.drawable.defualt_icon);
						}
						
				 holder.user_grade.setText(list.get(position).getPost_actor().getLevel()+"");
				 if (list.get(position).getExtra_data()!=null) {
						holder.user_address.setText(list.get(position).getExtra_data().getBaby_address());
					}
			}
			 
			 holder.user_head.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
							go(PersonCenterActivity.class, PersonCenterActivity.STR_ACTOR_ID, top_postben.getPost_actor().getActor_id());
						
					}
				});
				if (null!=top_postben.getExtra_data()) {
					if (null!=top_postben.getExtra_data().getBaby_days()) {
						switch (top_postben.getExtra_data().getStatus()) {
						case 1:
							holder.user_age.setText(DateUtil.getDue_date(top_postben.getExtra_data().getBaby_days()));
							break;
						case 2:
							holder.user_age.setText(DateUtil.getDayTip(top_postben.getExtra_data().getBaby_days()));
							break;
						case 3:
							holder.user_age.setText("6岁+");
							break;

						default:
							holder.user_age.setText("");
							break;
						}
					}else {
						holder.user_age.setText("");
					}
				}else {
					holder.user_age.setText("");
				}	
			holder.user_content.setText(list.get(position).getMessage());
			holder.user_time.setText(DateUtil.gettopicDate(list.get(position).getPost_time()));
			if (list.get(position).getParent_id()>0) {
				holder.reanswer_div.setVisibility(View.VISIBLE);
				if (list.get(position).getExtra_data()!=null) {
					holder.topic_reanser_name.setText(list.get(position).getExtra_data().getParent_post_actor_name());
					holder.topic_reanser_content.setText(list.get(position).getExtra_data().getParent_post_content());
				}
			}else {
				holder.reanswer_div.setVisibility(View.GONE);
			}
			boolean isHas_image = list.get(position).isHas_image() ;
			if (isHas_image) {
				holder.topic_user_pic.setVisibility(View.VISIBLE);
				final TopicAndPostBean bean = list.get(position) ;
				doholderpicdata(holder,bean.getFile_metas());
			}else {
				holder.topic_user_pic.setVisibility(View.GONE);
			}
			if (!is_praises) {
				if (praisesstate.getPraisesState(list.get(position)
						.getPost_id())) {
					Log.e("alan", "--------------likes-true---");
					 holder.user_choose_praise.setSelected(true);
					 holder.user_choose_praise.setTextColor(Color.parseColor("#ff9847"));
					 holder.user_choose_praise.setText(top_postben.getLikes_count()+1+"");
				} else {
					Log.e("alan", "--------------likes----false");
					 holder.user_choose_praise.setSelected(false);
					 holder.user_choose_praise.setTextColor(Color.parseColor("#6e6e6e"));
					 holder.user_choose_praise.setText(top_postben.getLikes_count()+"");
					;
				}
			}
			
			return convertView;
		}

		public void doholderpicdata(ViewHolder holder,
				final ArrayList<FileMetas> file_meta) {
			picture_bitmapUtil.configDefaultLoadingImage(R.drawable.iask_config_picture);
			if (file_meta.size() == 1) {
				holder.topic_picture1.setVisibility(View.GONE);
				holder.topic_picture2.setVisibility(View.GONE);
				holder.topic_picture3.setVisibility(View.GONE);
				String url = file_meta.get(0).getDownload_urls().getBig().getUrl();
				Log.e("alan", "-------------------------------url:+url");
				picture_bitmapUtil.display(holder.topic_user_pic, url);
			}
			if (file_meta.size() == 2) {
				holder.topic_picture1.setVisibility(View.VISIBLE);
				holder.topic_picture2.setVisibility(View.VISIBLE);
				holder.topic_picture3.setVisibility(View.GONE);
				String url = file_meta.get(0).getDownload_urls().getMiddle().getUrl();
				picture_bitmapUtil.display(holder.topic_picture1, url);
				String url2 = file_meta.get(1).getDownload_urls().getMiddle().getUrl();
				picture_bitmapUtil.display(holder.topic_picture2, url2);
				holder.topic_user_pic.setBackgroundColor(Color.parseColor("#01000000"));
			}
			if (file_meta.size() == 3) {
				holder.topic_picture1.setVisibility(View.VISIBLE);
				holder.topic_picture2.setVisibility(View.VISIBLE);
				holder.topic_picture3.setVisibility(View.VISIBLE);
				String url = file_meta.get(0).getDownload_urls().getMiddle().getUrl();
				picture_bitmapUtil.display(holder.topic_picture1, url);
				String url2 = file_meta.get(1).getDownload_urls().getMiddle().getUrl();
				picture_bitmapUtil.display(holder.topic_picture2, url2);
				String url3 = file_meta.get(2).getDownload_urls().getMiddle().getUrl();
				picture_bitmapUtil.display(holder.topic_picture3, url3);
				holder.topic_user_pic.setBackgroundColor(Color.parseColor("#01000000"));
			}
			holder.topic_user_pic
			.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					lookbigimage(file_meta, 0);
				}
			});
			holder.topic_picture1
					.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							lookbigimage(file_meta, 0);
						}
					});
			holder.topic_picture2
					.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							lookbigimage(file_meta, 1);
						}
					});
			holder.topic_picture3
					.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							lookbigimage(file_meta, 2);
						}
					});
		}
		
		class ViewHolder {
			 AsyncImageView user_head ;
			 ImageView topic_picture1,topic_picture2,topic_picture3;
			 LinearLayout topic_user_pic ,reanswer_div;
			 TextView  user_name,user_time,user_grade,
			 user_age,user_address,user_content,user_choose_praise,
			 topic_reanser_name,topic_reanser_content,user_laye;
			 Button user_result ,user_tool_but;
			
		}
	}
	public void lookbigimage(ArrayList<FileMetas> file_meta,int position) {
		Intent intent = new Intent(mContext, LookImageActivity.class);
		intent.putExtra("list",  (Serializable)file_meta);
		intent.putExtra("position",  position);
		TopicAndResultActivity.this.startActivity(intent);
	}
	//分享的对话框
	public void showtopictoolsdilog(final String informed_item_id,final String informed_item_type,final String coment,final String imageUrl) {
		 topic_tool_dialog = new Dialog(this, R.style.bubble_dialog);
		topic_tool_dialog.setCanceledOnTouchOutside(true);
		Window dialogWindow = topic_tool_dialog.getWindow();
		WindowManager manager = this.getWindowManager();
		LayoutParams params = dialogWindow.getAttributes();// 获取LayoutParams
		dialogWindow.setGravity(Gravity.BOTTOM);
		params.width = manager.getDefaultDisplay().getWidth();
		dialogWindow.setAttributes(params);
		topic_tool_dialog.setContentView(R.layout.topic_tools);
		topic_tool_dialog.show();
		mFrame.setVisibility(View.VISIBLE);
		
		
		topic_tool_dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
			
			@Override
			public void onDismiss(DialogInterface dialog) {
				
				mFrame.setVisibility(View.GONE);
			}
		});
		
		
		topic_tool_dialog.findViewById(R.id.share_weibo).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
//				initWeiBo(coment);
				mUmShare.OpenShare(coment, imageUrl);
				topic_tool_dialog.dismiss();
				mFrame.setVisibility(View.GONE);
			}
		});
		topic_tool_dialog.findViewById(R.id.share_weixin).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//initWeiXin(coment);
			}
		});
		topic_tool_dialog.findViewById(R.id.topic_report).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(TopicAndResultActivity.this,ReportActivity.class);
				intent.putExtra(STR_GROUP_ID, group_id);
				intent.putExtra(STR_REPORT_ID, informed_item_id);
				intent.putExtra(STR_REPORT_TYPE, informed_item_type);
				startActivityForResult(intent, 2655);
				topic_tool_dialog.dismiss();
				mFrame.setVisibility(View.GONE);
			}
		});
		topic_tool_dialog.findViewById(R.id.cance).setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				topic_tool_dialog.dismiss();
				mFrame.setVisibility(View.GONE);
			}
		});
	}
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == -1) {
			String path = null;
			try {
				is_clear_edite = false ;
				path = selToolData.setPicture(requestCode, resultCode, data);
				// 第一次是拍照或者选择照片 回来，第二次才是 裁剪完成
				Log.e("alan", "------------------path:"+path);
				ImageBean bean = new ImageBean();
				bean.setPath(path);
				photopath.add(bean);
				selToolData.setPhotoList(photopath);
				setImage();
				if (requestCode == CameraHelp.SURVEY_PHOTO_ZOOM) {
				//裁剪完成的.
				}
			} catch (Throwable ee) {
				QLog.debug(TAG, "内存不足===!!!!!!1");
				Toast.makeText(this, "内存不足", Toast.LENGTH_SHORT).show();
				// System.gc();
				path = null;
			}
			if (path != null) {
			}
		}
	}
	public void setImage() {
		int size = photopath.size();
		if (size == 0) {
			seltool_imgs.setVisibility(View.GONE);
			seltool_imgs_div_1.setVisibility(View.GONE);
			seltool_imgs_div_2.setVisibility(View.GONE);
			seltool_imgs_div_3.setVisibility(View.GONE);
		} else if (size == 1) {
			seltool_imgs.setVisibility(View.VISIBLE);
			seltool_imgs_div_1.setVisibility(View.VISIBLE);
			seltool_imgs_div_2.setVisibility(View.GONE);
			seltool_imgs_div_3.setVisibility(View.GONE);
			Bitmap bitmap1 = BitmapFactory.decodeFile(photopath.get(0).getPath());
			mBitmapRefs.add(new SoftReference<Bitmap>(bitmap1));
			photo1.setImageBitmap(bitmap1);
		} else if (size == 2) {
			seltool_imgs.setVisibility(View.VISIBLE);
			seltool_imgs_div_1.setVisibility(View.VISIBLE);
			seltool_imgs_div_2.setVisibility(View.VISIBLE);
			seltool_imgs_div_3.setVisibility(View.GONE);
			Bitmap bitmap1 = BitmapFactory.decodeFile(photopath.get(0).getPath());
			photo1.setImageBitmap(bitmap1);
			Bitmap bitmap2 = BitmapFactory.decodeFile(photopath.get(1).getPath());
			photo2.setImageBitmap(bitmap2);
			mBitmapRefs.add(new SoftReference<Bitmap>(bitmap1));
			mBitmapRefs.add(new SoftReference<Bitmap>(bitmap2));
			String mString= "22";
			int id =Integer.parseInt(mString);

		} else if (size == 3) {
			seltool_imgs.setVisibility(View.VISIBLE);
			seltool_imgs_div_1.setVisibility(View.VISIBLE);
			seltool_imgs_div_2.setVisibility(View.VISIBLE);
			seltool_imgs_div_3.setVisibility(View.VISIBLE);
			Bitmap bitmap1 = BitmapFactory.decodeFile(photopath.get(0).getPath());
			photo1.setImageBitmap(bitmap1);
			Bitmap bitmap2 = BitmapFactory.decodeFile(photopath.get(1).getPath());
			photo2.setImageBitmap(bitmap2);
			Bitmap bitmap3 = BitmapFactory.decodeFile(photopath.get(2).getPath());
			photo3.setImageBitmap(bitmap3);
			mBitmapRefs.add(new SoftReference<Bitmap>(bitmap1));
			mBitmapRefs.add(new SoftReference<Bitmap>(bitmap2));
			mBitmapRefs.add(new SoftReference<Bitmap>(bitmap3));
		}
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.title_xiala:
			if (title_xiala.isSelected()) {
				title_xiala.setSelected(false);
			} else {
				title_xiala.setSelected(true);
				initPopupWindow(title_xiala,mtListView);
			}
			
			break;
		case R.id.user_tquestion:
			if (mApplication.mMyUser.iAnonymousToken()) {
				Intent intent=new Intent(TopicAndResultActivity.this,RegAndLoginActivity.class);
				intent.putExtra(KidAction.FROM, "");
				startActivity(intent);
			}else {
				if (!user_tquestion.isSelected()) {
					addfavorites(topicbean.getTopic_id()+"");
				}else {
					deltfavorites(topicbean.getTopic_id()+"");
				}
			}
			
			
			break;
		case R.id.user_tool_but:
			if (mApplication.mMyUser.iAnonymousToken()) {
				showDialogImpl();
			}else {
				showtopictoolsdilog(topicbean.getTopic_id()+"","post",topicbean.getTopic_id()+"","");
			}
			
			break;
		case R.id.user_choose_praise:
			if (mApplication.mMyUser.iAnonymousToken()) {
				Intent intent=new Intent(TopicAndResultActivity.this,RegAndLoginActivity.class);
				intent.putExtra(KidAction.FROM, "");
				startActivity(intent);
			}else {
				if (top_is_praises) {
					deltpraises(topicbean.getTopic_id(),true,user_choose_praise);
				}else {
					addpraises(topicbean.getTopic_id(),true,user_choose_praise);
				}
				
			}
			
			break;
		case R.id.topic_answer_send:
			if (null==topicbean) {
				Toast.makeText(mContext, "请检查网络设置，然后重新加载数据，在发送数据", Toast.LENGTH_LONG).show();
				hideKeyBorad(topic_answer_input);
				return ;
			}
			
			
			if (topic_answer_input.getText().toString().trim().length() >1&&topic_answer_input.getText().toString().trim().length()<600) {
				if (photopath.size()>0) {
					File file = new File(photopath.get(0).getPath());
					putphoto(file);
				}else {
					
					postresult(topic_answer_input.getText().toString());
					
				}
			}else {
				Toast.makeText(mContext, "请输入2-600个字符", Toast.LENGTH_SHORT)
				.show();
				return;
			}
			
			
			break;
		case R.id.close1:
			seltool_imgs_div_1.setVisibility(View.GONE);
			photopath.remove(0);
			setImage();
			break;
		case R.id.close2:
			seltool_imgs_div_3.setVisibility(View.GONE);
			photopath.remove(1);
			setImage();
			break;
		case R.id.close3:
			seltool_imgs_div_3.setVisibility(View.GONE);
			photopath.remove(2);
			setImage();
			break;
		case R.id.main_left:
			if (topic_answer_input.getText().toString().length()>0||photopath.size()>0) {
				inintdialog();
			}else {
				hideKeyBorad(topic_answer_input);
				finish();
			}
			break;
		case R.id.topic_answer_input:
			if (mApplication.mMyUser.iAnonymousToken()) {
				Intent intent=new Intent(TopicAndResultActivity.this,RegAndLoginActivity.class);
				intent.putExtra(KidAction.FROM, "");
				startActivity(intent);
			}else {
				showKeyBorad(topic_answer_input);
				selToolData.setVisibility(View.VISIBLE);
				selToolData.setKeyBoardState(true);
				topic_answer_send.setBackgroundResource(R.drawable.topic_send_bg);
			}
		default:
			break;
		}
	}
	public void putphoto(File file) {
		showProgress("正在发送请稍等...");
		String  pageurl = KidConfig.UPLOAD_PHOTO;
		HttpBaseRequest request  =  Wxxr.getInstance().uploadFile(pageurl,file);
		 TaskManager.startHttpRequest(request, new putphotoTag(),  FileMetas.class);
	}
	class putphotoTag implements ITag {

		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			if (t instanceof FileMetas) {
				FileMetas bean = (FileMetas)t;
				Log.e("alan", "---------------getDownload_url---path:"+bean.getDownload_urls().getOrigin().getUrl());
				ImageBean ibean = new ImageBean();
				ibean.setFile_id(bean.getFile_id());
				photopath.remove(0);
				nt_photopath.add(ibean);
				if (photopath.size()>0) {
					File file = new File(photopath.get(0).getPath());
					putphoto(file);
				}else {
					postresult(topic_answer_input.getText().toString());
				}
				
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "图片上传失败", 1).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
	public void addpraises(int post_id,boolean istop ,TextView praise) {
		showProgress("正在发送请稍等...");
		String  pageurl = KidConfig.ADD_PRAISES;
		HttpParameters bodyParams = new HttpParameters();
		bodyParams.put("verb", "group_post");
		bodyParams.put("target_id", post_id+"");
		HttpBaseRequest request  =  Wxxr.getInstance().postBaseRequest(pageurl, bodyParams,null);
		 TaskManager.startHttpRequest(request, new addpraisesTag(post_id,request,istop,praise),  ResultBean.class);
	}
	class addpraisesTag implements ITag {
		private int id ;
		HttpBaseRequest request ;
		boolean istop ;
		TextView praise;
		public addpraisesTag(int id,HttpBaseRequest request,boolean istop,TextView praise){
			this.id = id ;
			this.request = request ;
			this.istop = istop ;
			this.praise = praise ;
		}
		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof ResultBean) {
				ResultBean bean = (ResultBean)t;
				if (bean.getError()==null) {
					is_praises = false;
					top_is_praises =true ;
					Toast.makeText(mContext, "赞成功", Toast.LENGTH_SHORT).show();
					if (!istop) {
						praisesstate.setPraisesState(id,true);
					}else {
						praise.setText(topic_praisecount+1+"");
						praise.setTextColor(Color.parseColor("#ff9847"));
						praise.setSelected(true);
					}
					adapter.notifyDataSetChanged();
				}else {
					Toast.makeText(mContext, "失败"+bean.getDesc(), Toast.LENGTH_SHORT).show();
				}
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "失败", Toast.LENGTH_SHORT);
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			request.cancel();
		}
		
	}
	//回复
	private void postresult(String message) {
		
		showProgress("正在发送请稍等...");
		String  pageurl = KidConfig.POSTS_TOPIC+topicbean.getTopic_id();
		HttpParameters bodyParams = new HttpParameters();
		try {
			message = URLEncoder.encode(message, "utf8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (nt_photopath.size()>0) {
			StringBuffer sb = new StringBuffer();
			if (nt_photopath.size()>1) {
				sb.append(nt_photopath.get(0).getFile_id());
				for (int i = 1; i < nt_photopath.size(); i++) {
					sb.append(",").append(nt_photopath.get(i).getFile_id());
				}
			}else if (nt_photopath.size()==1) {
				sb.append(nt_photopath.get(0).getFile_id());
			}
			bodyParams.put("file_ids", sb.toString());
		}
		bodyParams.put("message", message);
		if (!parent_id.equals("")) {
			bodyParams.put("parent_id", parent_id);
		}
		if (selToolData.getCheckBoxIsCheck()) {
			bodyParams.put("is_anonymous", "1");
		}else {
			bodyParams.put("is_anonymous", "0");
		}
		HttpBaseRequest request  =  Wxxr.getInstance().postBaseRequest(pageurl, bodyParams,null);
		 TaskManager.startHttpRequest(request, new postresultTag(),  TopicAndPostResultBean.class);
		 
		 
	}
	
	class postresultTag implements ITag {

		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof TopicAndPostResultBean) {
				TopicAndPostResultBean bean = (TopicAndPostResultBean)t;
				if (bean.getError()==null) {
					hideKeyBorad(topic_answer_input);
					topic_answer_input.setText("");
					photopath.clear();
					nt_photopath.clear();
					seltool_imgs.setVisibility(View.GONE);
					MobclickAgent.onEvent(mContext, "post_counts");
					Toast.makeText(mContext, "回复成功", Toast.LENGTH_SHORT)
					.show();
					if (bean.getStats().getDay()==1) {
						MobclickAgent.onEvent(mContext, "day_post_counts");
					}else if (bean.getStats().getWeek()==1) {
						MobclickAgent.onEvent(mContext, "week_post_counts");
					}else if (bean.getStats().getMonth()==1){
						MobclickAgent.onEvent(mContext, "month_post_counts");
					}
					cursor = 0;
					topicandpostlist= new ArrayList<TopicAndPostBean>() ;
					getTopiclist();
				}else {
					Toast.makeText(mContext, "失败"+bean.getDesc(), Toast.LENGTH_SHORT).show();
				}
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "失败", Toast.LENGTH_SHORT);
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
	
	//收藏
	public void addfavorites(String post_id) {
		showProgress("正在发送请稍等...");
		Log.e("alan", "------addfavorites------post_id:"+post_id);
		String  pageurl = KidConfig.ADD_FAVORITES;
		HttpParameters bodyParams = new HttpParameters();
		bodyParams.put("verb", "group_topic");
		bodyParams.put("target_id", post_id);
		HttpBaseRequest request  =  Wxxr.getInstance().postBaseRequest(pageurl, bodyParams,null);
		 TaskManager.startHttpRequest(request, new addfavoritesTag(false),  InformsBean.class);
	}
	public void deltpraises(int post_id,boolean istop,TextView praises) {
		showProgress("正在发送请稍等...");
		String  pageurl = KidConfig.ADD_PRAISES;
		HttpParameters bodyParams = new HttpParameters();
		bodyParams.put("verb", "group_post");
		bodyParams.put("target_id", post_id+"");
		HttpBaseRequest request  =  Wxxr.getInstance().deltteRequest(pageurl, bodyParams);
		 TaskManager.startHttpRequest(request, new deltpraisesTag(post_id,request,istop,praises),  ResultBean.class);
	}
	class deltpraisesTag implements ITag {
		private int id ;
		HttpBaseRequest request ;
		boolean istop ;
		private TextView praises;
		public deltpraisesTag(int id,HttpBaseRequest request,boolean istop,TextView praises){
			this.id = id ;
			this.request = request ;
			this.istop = istop ;
			this.praises =praises ;
		}
		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof ResultBean) {
				ResultBean bean = (ResultBean)t;
				if (bean.getError()==null) {
					is_praises = false;
					top_is_praises =false ;
					Toast.makeText(mContext, "取消赞成功", Toast.LENGTH_SHORT).show();;
					
					if (!istop) {
						praisesstate.setPraisesState(id,false);
					}else {
						if (topic_praisecount>1) {
							praises.setText(topic_praisecount+"");
						}else {
							praises.setText(topic_praisecount+"");
						}	
						praises.setTextColor(Color.parseColor("#6e6e6e"));
						praises.setSelected(false);
					}
					adapter.notifyDataSetChanged();
				}
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
	public void deltfavorites(String post_id) {
		showProgress("正在发送请稍等...");
		HttpParameters bodyParams = new HttpParameters();
		bodyParams.put("verb", "group_topic");
		bodyParams.put("target_id", post_id);
		String  pageurl = KidConfig.ADD_FAVORITES;
		HttpBaseRequest request  =  Wxxr.getInstance().deltteRequest(pageurl, bodyParams);
		 TaskManager.startHttpRequest(request, new addfavoritesTag(true),  InformsBean.class);
	}
	class addfavoritesTag implements ITag {
		private Boolean isdelte ;
		public addfavoritesTag(boolean isdelte ){
			this.isdelte = isdelte ;
		}
		@Override
		public void refreshUI(Object t, DataState ds) {
			// TODO Auto-generated method stub
			finishProgress();
			if (t instanceof InformsBean) {
				InformsBean bean = (InformsBean) t;
				if (bean.getError() == null) {
					if (isdelte) {
						Toast.makeText(mContext, "取消收藏成功", Toast.LENGTH_SHORT)
								.show();
					} else {
						Toast.makeText(mContext, "收藏成功", Toast.LENGTH_SHORT)
								.show();
					}
					if (user_tquestion.isSelected()) {
						user_tquestion.setSelected(false);
						user_tquestion.setTextColor(Color.parseColor("#6e6e6e"));
						user_tquestion.setText("收藏");
					} else {
						user_tquestion.setSelected(true);
						user_tquestion.setTextColor(Color.parseColor("#ff9847"));
						user_tquestion.setText("已收藏");
					}
				} else {
					Toast.makeText(mContext, "失败" + bean.getDesc(),
							Toast.LENGTH_SHORT).show();
				}
			}
		}

		@Override
		public boolean refreshError(DataParseError parseError) {
			// TODO Auto-generated method stub
			finishProgress();
			Toast.makeText(mContext, "失败", Toast.LENGTH_SHORT).show();
			return false;
		}

		@Override
		public void refreshCancel() {
			// TODO Auto-generated method stub
			
		}
		
	}
	private void initWeiBo(String coment) {
		String sharecontent = null ;
		try {
			Intent t = new Intent(this, ShareWeiBo.class);
			sharecontent = "我在辣妈育儿，快来围观吧！" + coment
					+ "，【苹果、安卓手机免费下载】http://www.ykdllmyr.com/lmyr/apk/lmyr_latest.apk";
			t.putExtra(KidAction.SHARE_TIP, sharecontent);
			startActivity(t);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void initWeiXin(String coment) {
//		IWXAPI api = WeiXinUtil.getWXAPIFactoryAndReg(this);
//		int supportAPI = api.getWXAppSupportAPI();
//		if (supportAPI==0) {
//			Toast.makeText(mContext, "未安装微信！", 1).show();
//		}else {
//			WeiXinUtil weixin = new WeiXinUtil(this, api);
//		    weixin.shareWXWebToGroup("我在辣妈育儿，快来围观吧！",coment, null,null,true);
//		}
		
	}
	public void inintdialog() {
		dialog.showDialog(this, "温馨提示", "丢弃所有内容并退出?", true, new DialogCallBack() {
			
			@Override
			public void onClick(int what) {
				doClick(what);
			}
		});
	}
	protected void doClick(int what) {
		switch (what) {
		case IDialog.YES:
			TopicAndResultActivity.this.finish();
			break;
		case IDialog.CANCLE:
			dialog.dismissProgress(null);
			break;
		default:
			break;
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(KeyEvent.KEYCODE_BACK == keyCode){
			if (topic_answer_input.getText().toString().length()>0||photopath.size()>0) {
				inintdialog();
			}else {
				finish();
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	public void showDialogImpl() {
		 DialogImpl  dialog = new DialogImpl();
		 dialog.showDialog(this, "注意", "注册登录后，才可以分享给好友哦", false, new DialogCallBack(){

			@Override
			public void onClick(int what) {
				switch (what) {
				case IDialog.YES://升级
					startActivity();
					break;
				case IDialog.CANCLE://
					break;
				default:
					break;
				}
			}
			 
		 });
	}
	private void startActivity(){
		Intent  intent = new Intent(mContext, RegAndLoginActivity.class);
		intent.putExtra(KidAction.FROM, "");
		this.startActivity(intent);
	}
	/**
	 * 初始化友盟分享
	 */
	private void initUmShare(){
		mUmShare = new UmShareUtils(this);
	}
}
